Repository navigation
Fix STRICT_GROUPING rejecting numbers written without formatting - #772
Merged
giggsey merged 2 commits intoOct 26, 2026
Merged
Conversation
allNumberGroupsRemainGrouped() ports Java's normalizedCandidate.substring(...).startsWith(nationalSignificantNumber) as mb_substr($candidate, strlen($nsn)) === $nsn, which compares the text after the national significant number instead of its start. In regions with a national prefix this made findNumbers() with STRICT_GROUPING skip numbers written as one block, such as 4156667777 (US) or 02071234567 (GB), which Java finds and which EXACT_GROUPING already accepts. The matcher test data providers combined the case lists with the array union operator, which keeps only the first list's keys, so most cases never ran at the leniencies they were meant for, including the unformatted exact-grouping cases under STRICT_GROUPING. They now use array_merge(), which runs 338 matcher tests instead of 218.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #772 +/- ##
============================================
+ Coverage 85.86% 86.12% +0.26%
- Complexity 1319 1320 +1
============================================
Files 31 31
Lines 3445 3445
============================================
+ Hits 2958 2967 +9
+ Misses 487 478 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
findNumbers()withLeniency::STRICT_GROUPING()skips numbers written as one block of digits in regions that have a national prefix, although it finds them with the stricterEXACT_GROUPING():allNumberGroupsRemainGrouped()ports this check fromPhoneNumberMatcher.java:as
mb_substr($candidate, mb_strlen($nationalSignificantNumber)) === $nationalSignificantNumber. That compares the text after the firststrlen(nsn)characters with the NSN, not the start of the text, so the check almost never passes. It now usesstr_starts_with().The existing tests didn't catch this because the matcher data providers combine their lists with the array union operator (
self::dataStrictGroupingCases() + self::dataExactGroupingCases()). For lists with integer keys,+keeps the first list's keys and drops the overlapping ones from the next, so several cases never ran at the leniencies they were meant for. Among them were the unformatted exact-grouping cases (4156667777,4156667777 x 123,4156667777) under STRICT_GROUPING. The providers now usearray_merge(), which bringsPhoneNumberMatcherTestfrom 218 to 338 tests. Without the fix, the 3 cases above fail; with it, all 338 pass.I compared this branch with Java libphonenumber 9.0.41 on about 90,000 generated parse, format, as-you-type, short-number and
findNumbers()calls. The 57STRICT_GROUPINGmismatches from the first run are gone, and no new ones appear.vendor/bin/phpunit,php-cs-fixer fix --dry-runandphpstanpass. The one exception isLocaleTestdata set #174 (SH, "St. Helena"), which also fails on master with the current giggsey/locale.